
/*
author：shinion
date：2019-01-08
备注：所有带有author标注的注释
        均为shinion之后附加，有可能和原方法意思不同，以方法实际功能为准

*/

MyVideoPlayer = {}
MyVideoPlayer.videoRequestMap = {};
MyVideoPlayer.stream = 1;

/*
author：shinion
date：2019-01-08
根据simNo获取所有通道的视频，然后播放所有通道的视频
*/
MyVideoPlayer.previewAllChannelVideo = function( simNo)
{
    var url = globalConfig.webPath + "/videoCommand/getAllVehicleChannels.action";
    var param = {simNo:simNo};
    $.getJSON(url, param, function(result)
    {
        if(result.success)
        {
            var channels = result.data;
            var channelIdArray = [];
            var titles = [];
            $.each(channels, function(i,v)
            {
                titles.push(v.name);
                channelIdArray.push(v.code);
            })
            var vehicleId = 0;
            MyVideoPlayer.previewVideo(vehicleId, simNo, channelIdArray, titles);
        }
    });
}

/*
author:shinion
date:2019-01-07
播放实时视频


备注：本方法所有注释作者：shinion
*/
MyVideoPlayer.previewVideo = function( vehicleId,simNo,  channels, titles,viewCloseTime, armType)
{
    MyVideoPlayer.popupWindow = false;
    //     
	var stream = this.stream;
	var strSimNo =  simNo;
	if(simNo.length < 12)   
        strSimNo = "0" + simNo;
    //开始播放视频
    this.getVideoHandler().startVideo(strSimNo,channels, stream,titles,viewCloseTime, armType, true);
	for(var m = 0; m < channels.length; m++)
	{
		var ch = channels[m];
		var vs = new VideoStatus(vehicleId,simNo, ch, stream,titles[m]);
		var requestKey = simNo + "_" + ch;
		this.videoRequestMap[requestKey] = vs;
		vs.sendRealVideoRequest();//发送实时视频请求
	}
}
/*
author：shinion
date：2019-01-08
弹窗播放车辆视频
*/
MyVideoPlayer.previewPopupVideo = function( vehicleId,simNo,  channels, titles,viewCloseTime,armType)
{
    //
    MyVideoPlayer.popupWindow = true;
    var stream = 1;
    var strSimNo =  simNo;
    if(simNo.length < 12)
        strSimNo = "0" + simNo;
    this.getVideoHandler().startVideo(strSimNo,channels, stream,titles,viewCloseTime, armType, true);
    for(var m = 0; m < channels.length; m++)
    {
        var ch = channels[m];
        var vs = new VideoStatus(vehicleId,simNo, ch, stream,titles[m]);
        var requestKey = simNo + "_" + ch;
        this.videoRequestMap[requestKey] = vs;
        vs.sendRealVideoRequest();
    }
}

/*
author：shinion
date：2019-01-08
开始进行监听
*/
MyVideoPlayer.startListen = function( vehicleId,simNo,  channel)
{
    //
    var stream = 1;
    var strSimNo =  simNo;
    if(simNo.length < 12)
        strSimNo = "0" + simNo;
    return this.getVideoHandler().startListen(strSimNo,channel);
}

/*
author：shinion
date：2019-01-08
开始对讲

*/
MyVideoPlayer.startTalkback = function( vehicleId,simNo,  channel,audioSampleRate,encodeQuality)
{
    //
    var stream = 1;
    var strSimNo =  simNo;
    if(simNo.length < 12 && simNo != "broadcast")
        strSimNo = "0" + simNo;
    return this.getVideoHandler().startTalkback(strSimNo,audioSampleRate,encodeQuality);
}

/*
author：shinion
date：2019-01-08
结束对讲

*/
MyVideoPlayer.stopTalkback = function(simNo )
{
    var stream = 1;
    var strSimNo =  simNo;
    if(simNo.length < 12)
        strSimNo = "0" + simNo;
    return this.getVideoHandler().stopTalkback();
}

/*
author：shinion
date：2019-01-08
关闭所有的连接
*/
MyVideoPlayer.stopAll = function () {
    this.getVideoHandler().doCloseAll();
}

/*
author：shinion
date：2019-01-08


*/
MyVideoPlayer.isWindowPreviewing = function()
{
    var videoHandler = this.getVideoHandler();
    if(videoHandler == null)
        return false;
    return videoHandler.isWindowPreviewing();
}

/*
author：shinion
date：2019-01-08
停止监听
*/
MyVideoPlayer.stopListen = function(simNo )
{
    //
    var stream = 1;
    var strSimNo =  simNo;
    if(simNo.length < 12)
        strSimNo = "0" + simNo;
    return this.getVideoHandler().stopListen();
}

/*
author：shinion
date：2019-01-08
停止simNo指定通道的视频播放
*/
MyVideoPlayer.stopChannelPreview = function( vehicleId,simNo,  channels)
{
    //
    var stream = 1;
    var strSimNo =  simNo;
    if(simNo.length < 12)
        strSimNo = "0" + simNo;
    for(var m = 0; m < channels.length; m++)
    {
        var ch = channels[m];
        MyVideoPlayer.getVideoHandler().stopChannelPreview(strSimNo, ch, 1);
    }
}

/**
 * 清除该用户的所有请求
 */
MyVideoPlayer.clearRequest = function () {
    //如果刷新了页面，则此前所有的请求，都清掉
    var url = globalConfig.webPath + "/videoRequest/clear.action";
    var param = {};
    $.getJSON(url, param, function(result)
    {
        if(console)
            console.log("清除以前的播放请求:" + (result.success ? "成功" : "失败"));
    });
}
/*
author：shinion
date：2019-01-08
获取视频播放对象：是报警弹窗播放，还是实时视频页面播放

*/
MyVideoPlayer.getVideoHandler = function()
{
    if(MyVideoPlayer.popupWindow)
    {
        return $('#alarmVideoWindowIframe')[0].contentWindow;
    }
    var iframeWindow = null;
    //var refresh_tab = $('#mainTab').tabs('getSelected');
    var refresh_tab = $('#mainTab').tabs('getTab',"实时视频");
    if(refresh_tab)
    {
    var title = refresh_tab.panel('options').title;
        if( title.indexOf( "实时视频") >= 0 || title.indexOf("视频回放") >= 0)
        {
            //iframeWindow= refresh_tab.find('iframe')[0];
            iframeWindow =  $("#realTimeVideoIFrame")[0];
        }
    }

    if(iframeWindow)
        return iframeWindow.contentWindow; 

    return null;
}

